obj-m += linux_symbol.o
linux_symbol-objs := pagetable.o findoffsets.o

KERNELDIR := $(QEMUM_REPO)/linux
PWD := $(shell pwd)
ARCH := riscv
CROSS_COMPILE := $(RISCV)/bin/riscv64-unknown-linux-gnu-

.PHONY: check

check:
ifndef QEMUM_REPO
        @echo "QEMUM_REPO is not set! Have you source script/env.sh first?"
        exit 1
endif
ifndef RISCV
        @echo "RISCV is not set! Have you source script/env.sh first?"
        exit 1
endif

BUILD_DIR := $(QEMUM_REPO)/libvmi-riscv/build/libvmi-tools

all: check findoffset

findoffset: findoffsets.c
	mkdir -p $(BUILD_DIR)
	make -C $(KERNELDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE)  modules
	cp linux_symbol.ko $(BUILD_DIR)/linux_symbol.ko

clean:
	make -C $(KERNELDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) clean

